<template>
  <div>
    <!-- 面包屑部分 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/welcome' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片视图区域 -->
    <el-card>
      <el-row :gutter="20">
        <el-col :span="9">
          <el-input placeholder="请输入内容" clearable v-model="queryInfo.query" @clear='getOrdersList'>
            <el-button slot="append" icon="el-icon-search" @click="getOrdersList"></el-button>
          </el-input>
        </el-col>
      </el-row>
      <!-- 表格部分 -->
      <el-table :data="ordersList" border stripe>
        <el-table-column type="index"></el-table-column>
        <el-table-column label="订单编号" prop="order_number">
        </el-table-column>
        <el-table-column label="订单价格" prop="order_price">
        </el-table-column>
        <el-table-column label="是否付款" prop="order_pay">
          <template slot-scope="scope">
            <el-tag type="success" v-if="scope.row.order_pay == 1">已付款</el-tag>
            <el-tag type="danger" v-else>未付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="是否发货" prop="is_send">
        </el-table-column>
        <el-table-column label="下单时间" prop="create_time">
          <template slot-scope="scope">
            {{scope.row.create_time | dateFormat}}
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button type="primary" icon="el-icon-edit" size="mini" @click="editOrder(scope.row)"></el-button>
            <el-button type="success" icon="el-icon-location-outline" size="mini" @click="progress(scope.row)"></el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页区域 -->
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="queryInfo.pagenum"
        :page-sizes="[5, 10, 15, 20]" :page-size="queryInfo.pagesize" layout="total, sizes, prev, pager, next, jumper" :total="total">
      </el-pagination>
    </el-card>
    <!-- 编辑订单的对话框 -->
    <EditOrder ref="editOrder"></EditOrder>
    <Progress ref="progress"></Progress>
  </div>
</template>
<script>
import EditOrder from '../order/dialog/EditOrder'
import Progress from '../order/dialog/Progress'
export default {
  components: {
    EditOrder,
    Progress
  },
  data: function () {
    return {
      // 订单条数
      total: 0,
      queryInfo: {
        pagesize: 5,
        pagenum: 1,
        query: ''
      },
      // 订单列表
      ordersList: []
    }
  },
  created: function () {
    this.getOrdersList()
  },
  methods: {
    // 获取订单列表
    getOrdersList: async function () {
      const res = await this.$http.get('orders', { params: this.queryInfo })
      if (res.meta.status !== 200) {
        this.$message.warning('订单列表获取失败')
      }
      this.ordersList = res.data.goods
      this.total = res.data.total
    },
    // 监听pagesize改变事件
    handleSizeChange: function (newSize) {
      this.queryInfo.pagesize = newSize
      this.getOrdersList()
    },
    // 监听pagenum改变事件
    handleCurrentChange: function (newPagenum) {
      this.queryInfo.pagenum = newPagenum
      this.getOrdersList()
    },
    // 点击编辑，弹出对话框
    editOrder: function (row) {
      this.$refs.editOrder.dialogVisible = true
    },
    // 点击按钮，弹出对话框
    progress: function () {
      this.$refs.progress.getProgress()
      this.$refs.progress.dialogVisible = true
    }
  }
}
</script>
<style lang="less" scoped>
.el-row {
  margin-bottom: 20px;
}
.el-pagination {
  margin-top: 20px;
}
</style>
